package com.studio77.guessLyric.core;

import android.app.Activity;
import android.content.SharedPreferences;

import com.studio77.guessLyric.MainActivity;
import com.studio77.guessLyric.R;
import com.wiyun.engine.nodes.CharMap;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.sound.AudioManager;
import com.wiyun.engine.types.WYRect;

public class GameSystem {
	public static MainActivity AndroidContext;
	public static SharedPreferences SharedSettings;
	/**
	 * 屏幕宽度
	 */
	public static int Screen_Width = 480;

	/**
	 * 屏幕高度
	 */
	public static int Screen_Height = 800;

	/**
	 * 游戏行数
	 */
	public static int GameRows = 10;

	/**
	 * 游戏列数
	 */
	public static int GameColumns = 10;

	/**
	 * 游戏两边留空
	 */
	public static final int Margin_Side = 20;

	public static int GameMatrixStartY = 675;

	/**
	 * 字符框大小
	 */
	public static final float CharSize = 44;

	/**
	 * 字符框中的字符大小
	 */
	public static final int CharBlockFontSize = 30;

	// 按钮高度宽度
	public static final float KeyHeight = 48;
	public static final float KeyWidth = 48;

	// Tip
	public static final int TipFontSize = 24;

	// stage 相关
	public static final int stageCount = 152;

	public static void loadAllResource() {
		loadTexture();
		loadCharMap();
		loadSound();
		initSetting();
		// ADHelper.initAD();
	}

	private static void loadSound() {
		AudioManager.preloadEffect(R.raw.cancel);
		AudioManager.preloadEffect(R.raw.coin);
		AudioManager.preloadEffect(R.raw.enter);
	}

	public static CharMap charMap;

	private static void loadCharMap() {
		charMap = CharMap.make();
		for (int i = 0; i < 10; i++) {
			charMap.mapChar(WYRect.make(i * 30, 0, 30, 40),
					(i + "").toCharArray()[0]);
		}
	}

	public static Texture2D tex_background;
	public static Texture2D tex_stage_star;
	public static Texture2D tex_fengkuang;
	public static Texture2D tex_caigeci;
	public static Texture2D tex_yinfu;
	public static Texture2D tex_DaanItem;
	public static Texture2D tex_GameType1;
	public static Texture2D tex_GameType2;
	public static Texture2D tex_Head;
	public static Texture2D tex_Disc;
	public static Texture2D tex_Complete_Background;
	public static Texture2D tex_Coin;

	private static void loadTexture() {

		tex_background = Texture2D.makePNG(R.drawable.mainpage);
		tex_stage_star = Texture2D.makePNG(R.drawable.stage_star);
		tex_fengkuang = Texture2D.makePNG(R.drawable.title_crazy);
		tex_caigeci = Texture2D.makePNG(R.drawable.title_guess);
		tex_yinfu = Texture2D.makePNG(R.drawable.yf);
		tex_DaanItem = Texture2D.makePNG(R.drawable.daan_item);
		tex_GameType1 = Texture2D.makePNG(R.drawable.guess_type1);
		tex_GameType2 = Texture2D.makePNG(R.drawable.guess_type2);
		tex_Head = Texture2D.makePNG(R.drawable.head);
		tex_Disc = Texture2D.makePNG(R.drawable.disc);
		tex_Complete_Background = Texture2D
				.makePNG(R.drawable.complete_background);
		tex_Coin = Texture2D.makePNG(R.drawable.coin_yuan);

		tex_Coin.loadTexture();
		tex_Complete_Background.loadTexture();
		tex_Head.loadTexture();
		tex_Disc.loadTexture();
		tex_GameType1.loadTexture();
		tex_GameType2.loadTexture();
		tex_DaanItem.loadTexture();
		tex_yinfu.loadTexture();
		tex_fengkuang.loadTexture();
		tex_caigeci.loadTexture();
		tex_background.loadTexture();
		tex_stage_star.loadTexture();
	}

	private static void initSetting() {
		SharedSettings = AndroidContext.getPreferences(Activity.MODE_PRIVATE);
		StageManager.instance.initStageData();
	}
}
